import useVariable from "@/store/useVariable";

const useInitVariable = () => {
    const { variable, setVariable } = useVariable();

    const initSetVariable = (title: string, id: string) => {
        // 设置变量
        const existingIndex = variable.findIndex(item => item.id === id);
        if (existingIndex !== -1) {
            variable[existingIndex] = { label: title as string, value: id, id };
        } else {
            variable.push({ label: title as string || "LLM", value: id, id });
        }
        setVariable(variable);
    }

    const deteleVariable = (id: string) => {
        // 删除变量
        const existingIndex = variable.findIndex(item => item.id === id);
        if (existingIndex !== -1) {
            variable.splice(existingIndex, 1);
        }
        setVariable(variable);
    }
    return { initSetVariable, deteleVariable }
}
export default useInitVariable;